package jsi.service.dao;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
@SuppressWarnings("unchecked")
public class GenericDaoHibernateImpl<T, PK extends Serializable> extends HibernateDaoSupport implements
		GenericDao<T, PK> {

	private Class<T> type;

	public GenericDaoHibernateImpl(Class<T> type) {
		this.type = type;
	}

	
	public PK create(T o) {
		return (PK) getHibernateTemplate().save(o);
	}

	public T read(PK id) {
		return (T) getHibernateTemplate().get(type, id);
	}

	public void update(T o) {
		getHibernateTemplate().update(o);
	}

	public void delete(PK id) {
		T object = read(id);
		getHibernateTemplate().delete(object);
	}

	public List<T> listAll() {
		return getHibernateTemplate().loadAll(type);
	}


	public void saveOrUpdate(T transientObject) {
		getHibernateTemplate().saveOrUpdate(transientObject);
		
	}
}
